package com.sudo.demo.security.config;

import com.sudo.demo.security.handler.CustomAccessDeniedHandler;
import com.sudo.demo.security.handler.CustomAuthenticationEntryPoint;
import com.sudo.demo.security.handler.CustomAuthenticationFailureHandler;
import com.sudo.demo.security.handler.CustomAuthenticationSuccessHandler;
import com.sudo.demo.security.util.JwtUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;


/**
 * Bean初始化配置
 *
 * @author DayDayUp
 * create on 2023-08-09
 **/
public class BeanInitConfig {
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new CustomAuthenticationEntryPoint();
    }

    @Bean
    public AccessDeniedHandler accessDeniedHandler() {
        return new CustomAccessDeniedHandler();
    }

    @Bean
    public CustomAuthenticationFailureHandler customAuthenticationFailureHandler(){
        return new CustomAuthenticationFailureHandler();
    }

    @Bean
    public CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler(){
        return new CustomAuthenticationSuccessHandler();
    }

    @Bean
    public JwtUtil jwtUtil(JwtProperties jwtProperties){
        return new JwtUtil(jwtProperties);
    }
}
